System.Data.dll
Represents an attribute that demands permission to access ODBC resources. This class cannot be inherited.
Applies to: .NET Framework 1.0, 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, 4.7, 4.8
The ODBCPermissionAttribute
class is used to grant or deny specific permissions to classes or methods. By applying this attribute, you can control the level of access that code has to ODBC data sources. This is particularly important in managed code environments where security is enforced through code access security (CAS).
The attribute allows you to specify the ODBCPermissionAttribute.OdbcPermissionLevel
, which defines the granular level of permission. This could range from no access to full access for connecting to and manipulating ODBC data sources.
Initializes a new instance of the ODBCPermissionAttribute
class with the specified PermissionState.
Gets or sets the level of permission to grant to code.
Gets the security action that is associated with the security attribute.
Gets a unique identifier for the security attribute.
Gets or sets the state of the permission.
Creates and returns a new security permission object that corresponds to this security attribute.
Creating an ODBCPermissionAttribute to grant full permission.
using System;
using System.Security;
using System.Security.Permissions;
using System.Data.Odbc;
public class MyDataAccessClass
{
// Grant full ODBC permission to this method
[ODBCPermissionAttribute(SecurityAction.Demand, OdbcPermissionLevel.FullLinked or OdbcPermissionLevel.Connect)]
public void AccessOdbcDataSource()
{
// Code that accesses ODBC data sources goes here
Console.WriteLine("ODBC access granted.");
}
// Example of denying permission
[ODBCPermissionAttribute(SecurityAction.Deny, OdbcPermissionLevel.All)]
public void RestrictedOdbcAccess()
{
// This code will not be able to access ODBC data sources
Console.WriteLine("ODBC access denied by attribute.");
}
}
Requirement | Details |
---|---|
.NET Framework | Supported in all versions from 1.0 to 4.8. |
Namespaces | System.Data.Odbc |
Assembly | System.Data.dll |